import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  ManyToOne,
  CreateDateColumn,
  UpdateDateColumn,
  Unique,
} from 'typeorm';
import { Song } from './song.entity';
import { User } from '../user/user.entity';

@Entity()
@Unique(['song', 'user']) // 确保一个用户只能收藏一首歌一次
export class SongCollection {
  @PrimaryGeneratedColumn()
  id: number;

  @ManyToOne(() => Song, (song) => song.collections, { onDelete: 'CASCADE' })
  song: Song;

  @ManyToOne(() => User, { onDelete: 'CASCADE' })
  user: User;

  @CreateDateColumn()
  createdAt: Date;

  @UpdateDateColumn()
  updatedAt: Date;
}
